using System;
using System.Collections;
using PHSRAG.Insight21.Common.Pages;
using PHSRAG.Insight21.Policy;

namespace PHSRAG.Insight21.FormsManagement
{
    /// <summary>
    /// FTBEditor lets the user enter rich text for question options
    /// </summary>
    public partial class FTBEditor : BasePage
    {
        #region Constants

        private const string ItemTextKey = "itemText_6484EE16-4F51-4d3a-8A1C-21D1B409DFE6";
        private const string ParentControlKey = "parentControl_6484EE16-4F51-4d3a-8A1C-21D1B409DFE6";

        #endregion

        #region Private instance members

        private ICachePolicy pageCachePolicy;

        #endregion

        #region Page Events

        /// <summary>
        /// Displays the cached text in the FreeTextBox control.
        /// </summary>
        /// <param name="sender">Control that raised the event.</param>
        /// <param name="e">Arguments associated with the event.</param>
        protected void OnPageLoad(object sender, EventArgs e)
        {
            Hashtable incomingData = pageCachePolicy.GetCachedObject(Keys.IncomingDataKey) as Hashtable;
            if (incomingData != null)
            {
                itemText.Text = (string) incomingData[Keys.OptionTextKey];
                pageCachePolicy.Cache(ItemTextKey, itemText.Text);
                parentControl.Value = (string) incomingData[Keys.OptionTextControlName];
                pageCachePolicy.Cache(ParentControlKey, parentControl.Value);
                pageCachePolicy.UnCache(Keys.IncomingDataKey);
            }
            else
            {
                itemText.Text = (string) pageCachePolicy.GetCachedObject(ItemTextKey);
                parentControl.Value = (string) pageCachePolicy.GetCachedObject(ParentControlKey);
            }
        }

        #endregion

        #region Web Form Designer generated code

        /// <summary>
        /// Page Initialization
        /// </summary>
        /// <param name="e">Arguments associated with the event.</param>
        protected override void OnInit(EventArgs e)
        {
            //
            // CODEGEN: This call is required by the ASP.NET Web Form Designer.
            //
            InitializeComponent();
            base.OnInit(e);
            pageCachePolicy = (Policy.ICachePolicy) Session[Policy.Names.PageCachePolicyKey];
        }

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.Load += new System.EventHandler(this.OnPageLoad);
        }

        #endregion
    }
}